﻿using FriendStar.Domain.Entity.MainData;
using FriendStar.Domain.IRepository.MainData;
using FriendStar.Repository.MianData;
using System;
using System.Collections.Generic;
using System.Linq;
using SqlSugarRepository;
using FriendStar.Code;

namespace FriendStar.Application.MainData
{
    public class ProductionTypeApp
    {
        private static string UseUnit = Configs.GetValue("UseUnit");  

        private IProductionTypeRepository service = new ProductionTypeRepository();

        public List<ProductionTypeEntity> GetList(Pagination pagination, string keyword)
        {
            var expression = ExtLinq.True<ProductionTypeEntity>();
            if (!string.IsNullOrEmpty(keyword))
            {
                expression = expression.And(t => t.FProductionTypeNO.Contains(keyword));
                expression = expression.Or(t => t.FProductionTypeName.Contains(keyword));
            }
            return service.FindList(expression, pagination);
        }

        public ProductionTypeEntity GetForm(string keyValue)
        {
            return service.FindEntity(keyValue);
        }

        public void DeleteForm(string keyValue)
        {
            service.Delete(t => t.FProductionTypeID == keyValue);
        }

        public void SubmitForm(ProductionTypeEntity entity, string keyValue)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                service.Update(entity);
            }
            else
            {
                entity.FProductionTypeID = Common.GuId();
                entity.UseUnit = UseUnit;
                service.Insert(entity);
            }
        }
    }
}


